<script type="text/javascript">
	//List Configuration
	$j("#list_surgerypatient").jqGrid({
		url:'surgerypatient/list/<?php echo $parameters["id_patient"];?>',
		datatype:'json',
		mtype:'POST',
		colNames:['Cirugía', 'Edad Cirugía', 'Observaciones','Paciente'],
		colModel:[
		          {
			          name:'surgery_id',
			          index:'surgery_id', 
			          width:30, 
			          editable: true,
			          edittype: 'select',
			          editoptions: {
			          	value:{
			          		<?php
			          		
			          		 $surgeries = $parameters["surgeries"];				          			 
					  		 $count = count($surgeries);
					  		 for ($i = 0; $i < $count; $i++){
					  		 	echo $surgeries[$i]->id.":'".$surgeries[$i]->surgery_name."'";
					  		 	if (($i+1) < $count) echo ",";
					  		 	else echo "";
					  		 }
						    ?>
			          	}
			          }
			      },
			      {
			          name:'age_at_surgery', 
			          index:'age_at_surgery', 
			          width:20, 
			          editable: true,
			          align:"right"
			      },
		          {
			          name:'observations', 
			          index:'observations', 
			          width:50,
			          editable: true,
			          edittype: 'textarea',
			          editoptions: { rows:'3', cols:'30'}
			      },
			      {
				      name: 'patient_id',
				      index: 'patient_id',
				      edittype: 'text',
				      editoptions: {value: <?php echo $parameters["id_patient"];?>},
				      width: 10,
				      editable: true,
				      hidden: true
				   }
		],
		pager:'#gridpager_surgerypatient',
		loadtext: 'Cargando Cirugías del Paciente ...',
		rowNum:10,
		rowList:[10],
		sortname:'surgery_id',
		sortorder:'asc',
		autowidth:true,
		viewrecords:true,
		onSelectRow:function(id){},
		editurl:'surgerypatient/save/<?php echo $parameters["id_patient"];?>',
		scrollOffset:0
	});

	$j("#list_surgerypatient").setGridWidth("650",true);
	$j("#list_surgerypatient").setGridHeight(220);
	
	//Form editing
	$j("#list_surgerypatient").jqGrid(
				'navGrid',
				'#gridpager_surgerypatient',
				{
					edit:true,
					add:true,
					del:true,
					search:true
				},
				{
					width: 320,
					height: 160,
					closeAfterEdit: true,
					editCaption: "Modificar Cirugía de Paciente"
				},
				{
					width: 320,
					height: 160,
					closeAfterAdd: true,
					addCaption: "Nueva Cirugía de Paciente"
				},
				{
					msg: "¿Desea eliminar la cirugía seleccionada del paciente?",
					caption: "Eliminar Cirugía de Paciente",
					width:350
				}
		);
</script>
